package com.burstly.lib.component.networkcomponent.millennial;

import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Build;
import android.os.Bundle;
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;

class LocationValet
{
  private static final int TWO_MINUTES = 120000;
  private boolean mHasGpsPermission;
  private boolean mHasNetworkPermission;
  private Location mLastGoodLocation;
  private LocationListener mListener;
  private final LocationManager mLocationManager;
  private final Reference<ILocationValetListener> mValetListener;

  LocationValet(Context paramContext, ILocationValetListener paramILocationValetListener)
  {
    this.mValetListener = new WeakReference(paramILocationValetListener);
    this.mLocationManager = ((LocationManager)paramContext.getSystemService("location"));
    this.mListener = new ValetLocationListener(null);
    boolean bool2;
    if (paramContext.checkCallingOrSelfPermission("android.permission.ACCESS_COARSE_LOCATION") == 0)
    {
      bool2 = bool1;
      this.mHasNetworkPermission = bool2;
      if (paramContext.checkCallingOrSelfPermission("android.permission.ACCESS_FINE_LOCATION") != 0)
        break label83;
    }
    while (true)
    {
      this.mHasGpsPermission = bool1;
      return;
      bool2 = false;
      break;
      label83: bool1 = false;
    }
  }

  private boolean isBetterLocation(Location paramLocation1, Location paramLocation2)
  {
    if (paramLocation2 == null)
      return true;
    long l = paramLocation1.getTime() - paramLocation2.getTime();
    int i;
    int j;
    if (l > 120000L)
    {
      i = 1;
      if (l >= -120000L)
        break label60;
      j = 1;
      label38: if (l <= 0L)
        break label66;
    }
    label60: label66: for (int k = 1; ; k = 0)
    {
      if (i == 0)
        break label72;
      return true;
      i = 0;
      break;
      j = 0;
      break label38;
    }
    label72: if (j != 0)
      return false;
    int m = (int)(paramLocation1.getAccuracy() - paramLocation2.getAccuracy());
    int n;
    int i1;
    if (m > 0)
    {
      n = 1;
      if (m >= 0)
        break label145;
      i1 = 1;
      label107: if (m <= 200)
        break label151;
    }
    boolean bool;
    label145: label151: for (int i2 = 1; ; i2 = 0)
    {
      bool = isSameProvider(paramLocation1.getProvider(), paramLocation2.getProvider());
      if (i1 == 0)
        break label157;
      return true;
      n = 0;
      break;
      i1 = 0;
      break label107;
    }
    label157: if ((k != 0) && (n == 0))
      return true;
    return (k != 0) && (i2 == 0) && (bool);
  }

  private boolean isSameProvider(String paramString1, String paramString2)
  {
    if (paramString1 == null)
      return paramString2 == null;
    return paramString1.equals(paramString2);
  }

  Boolean startAquire(Boolean paramBoolean)
  {
    if (paramBoolean.booleanValue())
    {
      if (this.mHasGpsPermission)
        updateValetListeners(this.mLocationManager.getLastKnownLocation("gps"));
    }
    else
    {
      if ((Build.FINGERPRINT.startsWith("generic")) || (!this.mHasNetworkPermission))
        break label90;
      this.mLocationManager.requestLocationUpdates("network", 3000L, 0.0F, this.mListener);
    }
    while (true)
    {
      return Boolean.valueOf(true);
      if (!this.mHasNetworkPermission)
        break;
      updateValetListeners(this.mLocationManager.getLastKnownLocation("network"));
      break;
      label90: if (!this.mHasGpsPermission)
        break label115;
      this.mLocationManager.requestLocationUpdates("gps", 0L, 0.0F, this.mListener);
    }
    label115: return Boolean.valueOf(false);
  }

  void stopAquire()
  {
    this.mLocationManager.removeUpdates(this.mListener);
  }

  void updateValetListeners(Location paramLocation)
  {
    this.mLastGoodLocation = paramLocation;
    ILocationValetListener localILocationValetListener = (ILocationValetListener)this.mValetListener.get();
    if (localILocationValetListener != null)
      localILocationValetListener.onBetterLocationFound(paramLocation);
  }

  static abstract interface ILocationValetListener
  {
    public abstract void onBetterLocationFound(Location paramLocation);
  }

  private class ValetLocationListener
    implements LocationListener
  {
    private ValetLocationListener()
    {
    }

    public void onLocationChanged(Location paramLocation)
    {
      if (LocationValet.this.isBetterLocation(paramLocation, LocationValet.this.mLastGoodLocation))
        LocationValet.this.updateValetListeners(paramLocation);
    }

    public void onProviderDisabled(String paramString)
    {
    }

    public void onProviderEnabled(String paramString)
    {
    }

    public void onStatusChanged(String paramString, int paramInt, Bundle paramBundle)
    {
    }
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.burstly.lib.component.networkcomponent.millennial.LocationValet
 * JD-Core Version:    0.6.2
 */